function dict_type(tableId){
	document.location='../admin/dirDictType.action?type='+tableId;
}
function task_search(){
	var pars = $('#form1').serialize()+'&tSessionId='+new Date().valueOf();
	c_updatePars('dirTaskMini.action',pars,'submitId');
}
function task_del(id){
	$.dialog.confirm('你确定要删除当前任务吗？', 
		function(){
			$.post('delTask.action',{id:id},function(data){
				switch(data.result){
					case 0:
			    	$.dialog.tips("删除成功！",1,'succ.png');
			    	$('#r'+id).remove();
						break;
					case 1:
						$.dialog.alert(data.msg);
						break;
				}
			},'json');
		}, 
		function(){
			return;
		}
	);
}
function task_exec(id){
	$.dialog.confirm('你确定要执行当前操作吗？', 
		function(){
			$.post('execTask.action',{id:id},function(data){
				switch(data.result){
					case 0:
			    	$.dialog.tips("操作成功！",1,'succ.png');
						break;
					case 1:
						$.dialog.alert(data.msg);
						break;
				}
			},'json');
		}, 
		function(){
			return;
		}
	);
}
var topStep=1;
function getRowId(objName){
	var tObj=$('#'+objName)[0];
	var rows=tObj.rows.length-(topStep);
	return rows;
}

var dialog=null;
function task_add(id){
	dialog = $.dialog({
		id:'task_add_Dlg',
		title: '任务管理', 
		width: '600px',
		fixed:true,
		max: false,
    min: false,
    ok: function(){
        $('#taskForm').submit();
        return false;
    },
    okVal:isnull(id)?'添加':'保存',
    cancelVal: '关闭',
    cancel: true
	});
	$.ajax({
	    url:'getTask.action',
	    data:{id:id},
	    success:function(data){
	        dialog.content(data);
	    },
	    cache:false
	});
}

function task_submit(){
	try{
		  var pars = $('#taskForm').serialize()+'&tSessionId='+new Date().valueOf(); 
			var toUrl='addTask.action';
			if(!isnull($('#id').val())) 
				toUrl='editTask.action';
			$.post(toUrl,pars,function(data){
				switch(data.result){
					case 0:
						$.dialog.tips('任务添加成功！',1,'succ.png');
						task_newLine(data.msg);
						dialog.close();
						break;
					case 2:
						$.dialog.tips("任务修改成功！",1,'succ.png');
						task_editLine(data.msg);
						dialog.close();
						break;
					default:
						$.dialog.alert(data.msg);
						break;
				}
			},'json');
	}catch(ex){}	
}

function task_newLine(id){
	var tbl,row,cell;
	var rowId=getRowId('dictTable');
		tbl = $('#dictTable')[0];
		row = tbl.insertRow(rowId);
		row.id='r'+id;
		$('#r'+id).dblclick(function(){
	   	task_add(id)
		});
		var k=0;
		cell = row.insertCell(k++);
		cell.innerHTML ='<a href="javascript:task_add('+id+')">修改</a>';
		cell = row.insertCell(k++);
		cell.innerHTML ='<a href="javascript:task_del('+id+')">删除</a>';
		cell = row.insertCell(k++);
		cell.innerHTML ='<a href="javascript:task_exec('+id+')">执行</a>';

		cell = row.insertCell(k++);
		cell.innerHTML =$('#name')[0].value;

		cell = row.insertCell(k++);
		cell.innerHTML =$('#description')[0].value;

		cell = row.insertCell(k++);
		cell.innerHTML =$('#exeContent')[0].value;

		cell = row.insertCell(k++);
		cell.innerHTML =$('#exeCorn')[0].value;

		cell = row.insertCell(k++);
		cell.innerHTML =$('#openFlag').find("option:selected").text();
}


function task_editLine(id){
	var row=$('#r'+id)[0];
	var k=3;
	row.cells[k++].innerHTML =$('#name')[0].value;
	row.cells[k++].innerHTML =$('#description')[0].value;
	row.cells[k++].innerHTML =$('#exeContent')[0].value;
	row.cells[k++].innerHTML =$('#exeCorn')[0].value;
	row.cells[k++].innerHTML =$('#openFlag').find("option:selected").text();
}